#!/bin/bash
DIR="$( cd "$( dirname "$(readlink -f  ${BASH_SOURCE[0]})" )" && pwd )"
#当前脚本上一层路径
PARENTPATH=$(dirname ${DIR})
echo "first shell script ======"${PARENTPATH}
content=`cat ${PARENTPATH}/description`
for line in ${content}
do
	echo ${line%=*}
	sh ${PARENTPATH}/readline.sh ${line%=*}
done
# set root password
# 提取脚本赋予命令
if [[ ! -z $1 ]] && [[ -z ${root_password} ]]
then
  root_password=$1
fi
DIR=$( dirname "$(readlink -f  ${BASH_SOURCE[0]})" )
#当前脚本上一层路径
PARENTPATH=$(dirname ${DIR})
# 设置默认密码
if [[ -z ${root_password} ]]
then
  root_password=`cat ${PARENTPATH}/description | grep -E 'root_password' | awk -F '=' '{print $2}'`
fi
sudo passwd root << EOF
${root_password}
${root_password}
EOF
echo "SET ROOT PASSWORD SUCCESSFUL......................."
SSHSERVER=`dpkg -l | grep ssh-server | awk '{print $2}'`
if [[ -z ${SSHSERVER} ]]
then
  echo "not found"
  echo yes | sudo apt-get install openssh-server
  SSHSERVER=`ps -ef | grep sshd | grep -v grep | awk '{print $2}'`
  if [ -n ${SSHSERVER} ]
  then
    echo "instann ssh-server successful................."
  fi
else
  echo ${SSHSERVER}" install already..................."
fi
PERMITROOTNUMBER=`cat /etc/ssh/sshd_config | grep -n '#PermitRootLogin prohibit-password'| awk -F "[:]+" '{print $1}'`
READYPERMITROOT=`cat /etc/ssh/sshd_config | grep -n 'PermitRootLogin yes' | awk '{print $1}'`
if [ -z ${READYPERMITROOT} ]
then
  echo ${PERMITROOTNUMBER}"line add"
  sudo sed -i -e ''"${PERMITROOTNUMBER}"'a PermitRootLogin yes' /etc/ssh/sshd_config
  sudo /etc/init.d/ssh restart
fi
apt list --installed | grep open-vm-tools
if [[ $? -eq 1 ]]
then
  sudo apt-get install open-vm-tools -y
fi
apt list --installed | grep unzip
if [[ $? -eq 1 ]]
then
  sudo apt-get install uzip -y
fi
sh ${PARENTPATH}/pass.sh
echo y | (sudo apt-get install zssh valac cmake g++ intltool libgtk-3-dev libgee-0.8-dev libjson-glib-dev libsecret-1-dev libwnck-3-dev librsvg2-dev libreadline-dev libpcre2-dev gobject-introspection libgirepository1.0-dev gperf libxml2-utils)
echo y | (sudo apt-get install libatk1.0-0 libc6 libcairo-gobject2 libcairo2 libfontconfig1 libgdk-pixbuf2.0-0 libgee-0.8-2 libglib2.0-0 libgnutls30 libgtk-3-0 libice6 libjson-glib-1.0-0 libpango-1.0-0 libpangocairo-1.0-0 libpcre2-8-0 libreadline7 librsvg2-2 libsecret-1-0 libsm6 libstdc++6 libtinfo5 libwnck-3-0 libx11-6 libxext6 zlib1g lrzsz expect deepin-menu)
